package edu.psu.collegerecommendationtool.coreservlets;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

import edu.psu.collegerecommendationtool.model.DemographicInfo;
import edu.psu.collegerecommendationtool.model.UserBean;

@ManagedBean(name="modifyDemographic")
public class ModifyDemographicInfoBean {
@ManagedProperty(value="#{userBean}")
   private UserBean user;

   private String entered_state;
   private byte entered_age;
   private String entered_sex;
   private String entered_race;
   private String entered_relative1;
   private String entered_college1;
   private String entered_relative2;
   private String entered_college2;
   private String entered_relative3;
   private String entered_college3;
   private String entered_relative4;
   private String entered_college4;
   private String entered_relative5;
   private String entered_college5;

   private DemographicInfo demographicInfo;

   public UserBean getUser() {
      return user;
   }
   public void setUser(UserBean user) {
      this.user = user;
   }

   public String getEntered_state() {
      return entered_state;
   }
   public void setEntered_state(String entered_state) {
      this.entered_state = entered_state;
   }

   public byte getEntered_age() {
      return entered_age;
   }
   public void setEntered_age(byte entered_age) {
      this.entered_age = entered_age;
   }

   public String getEntered_sex() {
      return entered_sex;
   }
   public void setEntered_sex(String entered_sex) {
      this.entered_sex = entered_sex;
   }

   public String getEntered_race() {
      return entered_race;
   }
   public void setEntered_race(String entered_race) {
      this.entered_race = entered_race;
   }

   public String getEntered_relative1() {
      return entered_relative1;
   }
   public void setEntered_relative1(String entered_relative1) {
      this.entered_relative1 = entered_relative1;
   }

   public String getEntered_college1() {
      return entered_college1;
   }
   public void setEntered_college1(String entered_college1) {
      this.entered_college1 = entered_college1;
   }

   public String getEntered_relative2() {
      return entered_relative2;
   }
   public void setEntered_relative2(String entered_relative2) {
      this.entered_relative2 = entered_relative2;
   }

   public String getEntered_college2() {
      return entered_college2;
   }
   public void setEntered_college2(String entered_college2) {
      this.entered_college2 = entered_college2;
   }

   public String getEntered_relative3() {
      return entered_relative3;
   }
   public void setEntered_relative3(String entered_relative3) {
      this.entered_relative3 = entered_relative3;
   }

   public String getEntered_college3() {
      return entered_college3;
   }
   public void setEntered_college3(String entered_college3) {
      this.entered_college3 = entered_college3;
   }

   public String getEntered_relative4() {
      return entered_relative4;
   }
   public void setEntered_relative4(String entered_relative4) {
      this.entered_relative4 = entered_relative4;
   }

   public String getEntered_college4() {
      return entered_college4;
   }
   public void setEntered_college4(String entered_college4) {
      this.entered_college4 = entered_college4;
   }

   public String getEntered_relative5() {
      return entered_relative5;
   }
   public void setEntered_relative5(String entered_relative5) {
      this.entered_relative5 = entered_relative5;
   }

   public String getEntered_college5() {
      return entered_college5;
   }
   public void setEntered_college5(String entered_college5) {
      this.entered_college5 = entered_college5;
   }

   public DemographicInfo getDemographicInfo() {
      return demographicInfo;
   }
   public void setDemographicInfo(DemographicInfo demographicInfo) {
      this.demographicInfo = demographicInfo;
  }

////////////////////////////////////////////////////////////////////////

public String saveDemographicInfo() {
      boolean action = false;
      demographicInfo = user.getDemographicInfo();

      if ((!entered_state.equals(demographicInfo.getState())) &&
          (!entered_state.isEmpty())) {
         demographicInfo.setState(entered_state);
         action = true;
      }

      if ((entered_age != demographicInfo.getAge()) &&
          (0 != entered_age)) {
         demographicInfo.setAge(entered_age);
         action = true;
      }

      if ((!entered_sex.equals(demographicInfo.getSex())) &&
          (!entered_sex.isEmpty())) {
         demographicInfo.setSex(entered_sex);
         action = true;
      }

      if ((!entered_race.equals(demographicInfo.getRace())) &&
          (!entered_race.isEmpty())) {
         demographicInfo.setRace(entered_race);
         action = true;
      }

      if ((!entered_relative1.equals(demographicInfo.getRelative1())) &&
          (!entered_relative1.isEmpty())) {
         demographicInfo.setRelative1(entered_relative1);
         action = true;
      }
      if ((!entered_college1.equals(demographicInfo.getCollege1())) &&
          (!entered_college1.isEmpty())) {
         demographicInfo.setCollege1(entered_college1);
         action = true;
      }

      if ((!entered_relative2.equals(demographicInfo.getRelative2())) &&
          (!entered_relative2.isEmpty())) {
         demographicInfo.setRelative2(entered_relative2);
         action = true;
      }
      if ((!entered_college2.equals(demographicInfo.getCollege2())) &&
          (!entered_college2.isEmpty())) {
         demographicInfo.setCollege2(entered_college2);
         action = true;
      }

      if ((!entered_relative3.equals(demographicInfo.getRelative3())) &&
          (!entered_relative3.isEmpty())) {
         demographicInfo.setRelative3(entered_relative3);
         action = true;
      }
      if ((!entered_college3.equals(demographicInfo.getCollege3())) &&
          (!entered_college3.isEmpty())) {
         demographicInfo.setCollege3(entered_college3);
         action = true;
      }

      if ((!entered_relative4.equals(demographicInfo.getRelative4())) &&
          (!entered_relative4.isEmpty())) {
         demographicInfo.setRelative4(entered_relative4);
         action = true;
      }
      if ((!entered_college4.equals(demographicInfo.getCollege4())) &&
          (!entered_college4.isEmpty())) {
         demographicInfo.setCollege4(entered_college4);
         action = true;
      }

      if ((!entered_relative5.equals(demographicInfo.getRelative5())) &&
          (!entered_relative5.isEmpty())) {
         demographicInfo.setRelative5(entered_relative5);
         action = true;
      }
      if ((!entered_college5.equals(demographicInfo.getCollege5())) &&
          (!entered_college5.isEmpty())) {
         demographicInfo.setCollege5(entered_college5);
         action = true;
      }


      if(true == action) {
         user.setDemographicInfo(demographicInfo);
         user.saveDemographicInfo();
      }

      return ("ModifyInfoPage");
   }

}
